
    /*1.用正则表达式实现html编码（转义）*/
    function htmlEncodeByRegExp(str){  
        var temp = "";
            if(str.length == 0) return "";
            temp = str.replace(/&/g,"&amp;");
            temp = temp.replace(/</g,"&lt;");
            temp = temp.replace(/>/g,"&gt;");
            temp = temp.replace(/\s/g,"&nbsp;");
            temp = temp.replace(/\'/g,"&#39;");
            temp = temp.replace(/\"/g,"&quot;");
            return temp;
    };
    /*2.用正则表达式实现html解码（反转义）*/
    function htmlDecodeByRegExp(str){  
        var temp = "";
        if(str.length == 0) return "";
            temp = str.replace(/&amp;/g,"&");
            temp = temp.replace(/&lt;/g,"<");
            temp = temp.replace(/&gt;/g,">");
            temp = temp.replace(/&nbsp;/g," ");
            temp = temp.replace(/&#39;/g,"\'");
            temp = temp.replace(/&quot;/g,"\"");
            return temp;  
    };
    /*3.用正则表达式实现html编码（转义）（另一种写法）*/
    function html2Escape (sHtml) {
        return sHtml.replace(/[<>&"]/g,function(c){return {'<':'&lt;','>':'&gt;','&':'&amp;','"':'&quot;'}[c];});
    };
    /*4.用正则表达式实现html解码（反转义）（另一种写法）*/
    function escape2Html (str) {
        var arrEntities={'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};
        return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];});
    };
        

module.exports={htmlEncodeByRegExp,htmlDecodeByRegExp,html2Escape,escape2Html}
// module.exports={EncodeHtml}